﻿package {
	import flash.net.*;
	import flash.events.*;
	public class Playlist {

		private var xmlData:XML;
		private var pla:Player;
		
		private var album:String;
		private var artist:String;
	
		private var xmlLoader:URLLoader = new URLLoader();

		public function Playlist(url:URLRequest) {
			xmlLoader.addEventListener(Event.COMPLETE,test);
			xmlLoader.load(url);
		}
		
		private function test(e:Event):void {
			xmlData = new XML(e.target.data);
			this.artist = "Kings Of Leon";
			this.album = "Only By Night";
		}
		
		public function setPlayer(pla:Player):void{
			this.pla = pla;
		}
		
		public function getFilePath(trackTitle:String):String{
			var tmpXML:XMLList = xmlData.artist.(@name == artist).album.(@name == album).track.(@name == trackTitle).filepath;
			return "" + tmpXML;
		}
		
		public function playlist():Array{
			var tmpXML:XMLList = xmlData.artist.(@name == artist).album.(@name == album).track.@name;
			var retArray:Array = new Array(tmpXML.length());
			for(var i:int; i < tmpXML.length(); i++){
				retArray[i] = tmpXML[i];				
			}
			return retArray;
		}
		
		public function albumlist():Array{
			var tmpXML:XMLList = xmlData.artist.(@name == artist).album.@['name'];
			var retArray:Array = new Array(tmpXML.length());
			for(var i:int; i < tmpXML.length(); i++){
				retArray[i] = tmpXML[i];				
			}
			return retArray;
		}
		
		public function relatedArtists():Array{
			return new Array(1);			
		}
		
		public function relatedAlbums():Array{
			return new Array(1);			
		}
		
		public function chooseAlbum(alb:String){
			album = alb;
		}
		
		public function chooseArtist(art:String){
			album = art;
		}
	}
}